package com.livedocumentation.client.web.comments;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Button;
import com.livedocumentation.client.GWTEntryPoint;
import com.livedocumentation.client.model.Comment;
import com.livedocumentation.client.webservices.comments.SaveCommentRequest;

/**
 * 
 * @UserInterface
 */
public class ButtonSaveComment extends Button {

	public ButtonSaveComment(final String projectID, final String classPath) {

		this.setText("Save");
		this.addClickHandler(new ClickHandler() {

			@Override
			public void onClick(ClickEvent event) {

				Comment comment = new Comment();

				comment.setDescription(CommentsForm.textAreaComment.getValue());

				comment.setProjectID(projectID);

				comment.setClassPath(classPath);

				comment.setFacebookUser(GWTEntryPoint.facebookUser);

				SaveCommentRequest.sendPostRequest(comment);

				CommentsForm.textAreaComment.setValue(null);
			}
		});
	}
}